package com.vt.admin.controller;

import com.vt.admin.api.dto.OrganizationTree;
import com.vt.admin.api.dto.OrganizationTypeTree;
import com.vt.admin.api.entity.SysOrganization;
import com.vt.admin.api.entity.SysOrganizationType;
import com.vt.admin.service.SysOrganizationService;
import com.vt.common.core.util.R;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 组织
 */
@RestController
@RequestMapping("/organization")
@AllArgsConstructor
public class SysOrganizationController {
    private final SysOrganizationService organizationService;

    /**
     * 通过ID查询
     */
    @GetMapping("/{id}")
    public R<SysOrganization> get(@PathVariable String id) {
        return organizationService.getById(id);
    }

    /**
     * 通过ID查询
     */
    @GetMapping("/type/{typeId}")
    public R<SysOrganizationType> typeById(@PathVariable String typeId) {
        return organizationService.getTypeById(typeId);
    }

    @GetMapping("/tree")
    public R<List<OrganizationTree>> tree() {
        return new R(organizationService.tree());
    }

    @GetMapping("/typeTree")
    public R<List<OrganizationTypeTree>> typeTree() {
        return organizationService.typeTree();
    }

    @PostMapping("/type")
    public R<Boolean> typeSave(@RequestBody SysOrganizationType param) {
        return organizationService.typeSave(param);
    }

    @PostMapping
    public R<Boolean> save(@RequestBody SysOrganization organization){
        return organizationService.save(organization);
    }
}
